<?php
//src/Pyaf/GymBundle/Entity/Profesor.php
namespace Pyaf\GymBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
/**
 * Profesor
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Pyaf\GymBundle\Repository\ProfesorRepository")
 */
class Profesor implements UserInterface, \Serializable, EquatableInterface{

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="username", type="string", length=150, unique=true)
     * @Assert\NotBlank(message="Nombre de usuario es un campo requerido.")
     * @Assert\NotNull()
     * @Assert\MaxLength(150)
     */
    private $username;

    /**
     * @var string
     *
     * @ORM\Column(name="password", type="string", length=150)
     * @Assert\NotBlank(message="Password de usuario es un campo requerido.")
     * @Assert\NotNull()
     * @Assert\MaxLength(150)
     */
    private $password;

    /**
     * @ORM\ManyToMany(targetEntity="Rol", inversedBy="users")
     * @ORM\JoinTable(name="profesor_rol",
     *      joinColumns={@ORM\JoinColumn(name="profesor_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="rol_id", referencedColumnName="id")}
     *      )
     */
    protected $userRoles;
    
     /**
     * @ORM\Column(type="string", length=32)
     */
    private $salt;

    /**
     * @var Persona 
     * @ORM\OneToOne(targetEntity="Persona", cascade={"persist", "remove"})
     * @ORM\JoinColumn (name="persona_id", referencedColumnName="id", nullable=true)
     */
    private $persona;
    
    /**
    * @ORM\OneToMany(targetEntity="Clase", mappedBy="profesor")
    */
    protected $clases;
    
    /**
     * @ORM\OneToMany(targetEntity="Asistencia", mappedBy="profesor")
     */
    protected $asistencias;
    
    public function __construct()
    {
        $this->clases = new \Doctrine\Common\Collections\ArrayCollection();
        $this->roles = new \Doctrine\Common\Collections\ArrayCollection();
        $this->salt = md5(uniqid(null, true));
    }
    
    public function __toString()
    {
        return $this->getNombreCompleto();
    }

    public function getNombreCompleto()
    {
        return $this->persona->getNombre().' '.$this->persona->getApellido();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId() {
        return $this->id;
    }


    /**
     * Set persona
     *
     * @param \Pyaf\GymBundle\Entity\Persona $persona
     * @return Profesor
     */
    public function setPersona(\Pyaf\GymBundle\Entity\Persona $persona = null)
    {
        $this->persona = $persona;
    
        return $this;
    }

    /**
     * Get persona
     *
     * @return \Pyaf\GymBundle\Entity\Persona 
     */
    public function getPersona()
    {
        return $this->persona;
    }

    /**
     * Add clases
     *
     * @param \Pyaf\GymBundle\Entity\Clase $clases
     * @return Profesor
     */
    public function addClase(\Pyaf\GymBundle\Entity\Clase $clases)
    {
        $this->clases[] = $clases;
    
        return $this;
    }

    /**
     * Remove clases
     *
     * @param \Pyaf\GymBundle\Entity\Clase $clases
     */
    public function removeClase(\Pyaf\GymBundle\Entity\Clase $clases)
    {
        $this->clases->removeElement($clases);
    }

    /**
     * Get clases
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getClases()
    {
        return $this->clases;
    }

    /**
     * Add asistencias
     *
     * @param \Pyaf\GymBundle\Entity\Asistencia $asistencias
     * @return Profesor
     */
    public function addAsistencia(\Pyaf\GymBundle\Entity\Asistencia $asistencias)
    {
        $this->asistencias[] = $asistencias;
    
        return $this;
    }

    /**
     * Remove asistencias
     *
     * @param \Pyaf\GymBundle\Entity\Asistencia $asistencias
     */
    public function removeAsistencia(\Pyaf\GymBundle\Entity\Asistencia $asistencias)
    {
        $this->asistencias->removeElement($asistencias);
    }

    /**
     * Get asistencias
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getAsistencias()
    {
        return $this->asistencias;
    }

    /**
     * Set salt
     *
     * @param string $salt
     * @return Profesor
     */
    public function setSalt($salt)
    {
        $this->salt = $salt;
    
        return $this;
    }

    /**
     * Get salt
     *
     * @return string 
     */
    public function getSalt()
    {
        return $this->salt;
    }

    /**
     * Set username
     *
     * @param string $username
     * @return Profesor
     */
    public function setUsername($username)
    {
        $this->username = $username;
    
        return $this;
    }

    /**
     * Get username
     *
     * @return string 
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * Set password
     *
     * @param string $password
     * @return Profesor
     */
    public function setPassword($password)
    {
        $this->password = $password;
    
        return $this;
    }

    /**
     * Get password
     *
     * @return string 
     */
    public function getPassword()
    {
        return $this->password;
    }

    public function eraseCredentials() {
        
    }

    public function serialize() {
        return serialize(array(
            $this->id,
        ));
    }

    public function unserialize($serialized) {
        list (
            $this->id,
        ) = unserialize($serialized);
    }

    public function isEqualTo(UserInterface $user) {
        return $this->id === $user->getId();
    }

    /**
     * Add userRoles
     *
     * @param \Pyaf\GymBundle\Entity\Rol $userRoles
     * @return Profesor
     */
    public function addUserRole(\Pyaf\GymBundle\Entity\Rol $userRoles)
    {
        $this->userRoles[] = $userRoles;
    
        return $this;
    }

    /**
     * Remove userRoles
     *
     * @param \Pyaf\GymBundle\Entity\Rol $userRoles
     */
    public function removeUserRole(\Pyaf\GymBundle\Entity\Rol $userRoles)
    {
        $this->userRoles->removeElement($userRoles);
    }

    /**
     * Get userRoles
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getUserRoles()
    {
        return $this->userRoles;
    }

    /**
     * Get roles
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getRoles()
    {
        return $this->userRoles->toArray();
    }

}